var app = getApp();
var dateTimePicker = require('../../utils/dateTimePicker.js');
var date = new Date();
var currentYear = date.getFullYear();
var nextYear = currentYear + 1;

Page({

  data: {
    workarray:['冲床','定钉','整形','压支架','压铆钉','焊袖套','拉床','打珠','包装'],
    windex: 0,
    info:{},
    startDate:'2022-02-24',
    endDate:'2022-02-24',
    showgif:true,
    hArray: [
      {
        hou: 1,
        name: '白班'
      },
      {
        hou: 2,
        name: '夜班'
      }
    ],
    hname:'',
    banci:"",//默认白班
  },

  onLoad: function () {

    var that = this;
    if (!wx.getStorageSync('openid')) {
      app.error("请登录后再操作");
      return false;
    }

    var date = new Date();  
    //年  
    var Y = date.getFullYear();  
    //月  
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);  
    //日  
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();  
    var todate = Y+"-"+M+"-"+D;
    this.setData({
      startDate: todate,
      endDate: todate,
    });

      let banci = wx.getStorageSync('nowbc');
      if(banci){
        if(banci == "1"){
          this.setData({
            banci: 1,
            hname:'白班'
          });
        }else{
          this.setData({
            banci: 2,
            hname:'夜班'
          });
        }
       
      }else{
        this.setData({
          banci: 1,
          hname:'白班'
        });
      }

      that.getwork();
  },

  //角色变更事件
bindPickerChange_hx(e) {
  console.log('picker发送选择改变，索引为', e.detail.value);
　var hname = this.data.hArray[e.detail.value].name //根据索引去查对应的id
    if(e.detail.value == 0){
      　var banci = 1;
    }else{
      　var banci = 2;
    }
    this.setData({   //给变量赋值
        hname:hname,
        banci:banci
    })
 
},
 
  formSubmit: function (event) {
    var that = this;
    var sdate = that.data.startDate;
    var edate = that.data.endDate;
    var ban = that.data.banci;
    if(edate < sdate){
      app.error('结束时间必须大于开始时间');
      return false;
    }
    that.setData({ showgif: true});
    wx.request({
      url: app.apiUrl + '/api/kanban/tongji',
      data: {
        starttime:sdate,
        endtime:edate,
        ban:ban,
        openid:wx.getStorageSync('openid'),
      },
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: res=> {
        that.setData({ showgif: false});
        if(res.data.code == 0){
          wx.showModal({
            title: '温馨提示',
            content: res.data.msg,
            showCancel: false
          });
    
        }else{
          that.setData({ info: res.data.data});
        }
   
      }
    })



 
 
  
  },

  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      startDate: e.detail.value
    })
  },

  bindDateChange2: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      endDate: e.detail.value
    })
  },

//改变事件结束
changezt(){
  var that = this
  wx.showActionSheet({
    itemList: ['冲床','定钉','整形','压支架','压铆钉','焊袖套','拉床','打珠','包装',],
    success(res) {
      that.setData({ status: that.data.itemList[res.tapIndex]});
      that.setData({ choose: res.tapIndex+1});
   
    },
    fail(res) {
      console.log(res.errMsg)
    }
  })
},
  getwork(){
    var that = this
    let bc = that.data.banci
  wx.request({
    url: app.apiUrl + '/api/kanban/tongji',
    data: {
      openid:wx.getStorageSync('openid'),
      starttime: that.data.startDate,
      endtime: that.data.endDate,
      ban:bc
    },
    method: 'POST',
    header: { 'content-type': 'application/x-www-form-urlencoded' },
    success: res=> {
      that.setData({ showgif: false});
        if(res.data){
          that.setData({ info: res.data.data});
        }
    }
  })
},
 

 

})